# -*- coding: utf-8 -*-
require 'sinatra'
require 'sequel'

db = Sequel.connect('mysql2://root:root@localhost/md')

category= db[:category]
article = db[:article]
get '/:id' do
    @id = params[:id]
	@articles = article.where(:categoryid=>params[:id]).map([:id,:title]);
	@categories = category.map([:id, :name]);

    erb :'category/category'
end


get '/category/:id' do
	@id = params[:id]
	if @id then
		@articles = article.where(:categoryid=>params[:id]).map([:id,:title]);
	end
	@categories = category.map([:id, :name]);

    erb :'category/category'
end

get '/doc/:id' do
	@categories = category.map([:id, :name]);
	@article = article.where(:id=>params[:id]).first

	erb :'article'
end
